import hotshot, hotshot.stats

## Courtesy of http://www.biais.org/blog/index.php/2007/01/20/18-python-profiling-decorator
def profileit(printlines=1):
    """ Profiler """
    def _my(func):
        """ Profiler """
        def _func(*args, **kargs):
            """ Profiler """
            prof = hotshot.Profile("/tmp/profiling.data")
            res = prof.runcall(func, *args, **kargs)
            prof.close()
            stats = hotshot.stats.load("/tmp/profiling.data")
            stats.strip_dirs()
            stats.sort_stats('cumulative', 'calls')
            print ">>>---- Begin profiling print"
            stats.print_stats(printlines)
            print ">>>---- End profiling print"
            return res
        return _func
    return _my